import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home/index.vue'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/cartList/index.vue'
import ChecKout from '@/views/checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import Member from '@/views/Member/index.vue'
import MemberInfo from '@/views/Member/components/UserInfo.vue'
import MemberOrder from '@/views/Member/components/UserOrder.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: Layout,
      children: [
        {
          path: '',
          name: 'home',
          component: Home
        },
        {
          path: 'category/:id',
          name: 'category',
          component: Category
        },
        {
          path: 'category/sub/:id',
          name: 'subCategory',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          name: 'detail',
          component: Detail
        },
        {
          path: 'cartlist',
          name: 'cartList',
          component: CartList
        },
        {
          path: 'checkout',
          name: 'checKout',
          component: ChecKout
        },
        {
          path: 'pay/:id',
          name: 'Pay',
          component: Pay
        },
        {
          path: 'paycallback', // 注意路径，必须是paycallback
          component: PayBack
        },
        {
          path: 'member', 
          component: Member,
          children:[
          {
            path: '',
            component: MemberInfo
          },
          { path: 'order',
            component: MemberOrder
          }
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
  ],
  //路由滚动行为定制
  scrollBehavior() { 
    return {
      top: 0 //路由更新时 滚动到顶部
    }
  }
})

export default router
